package com.hp.controller;

import com.github.pagehelper.PageInfo;
import com.hp.entity.UserRole;
import com.hp.service.UserRoleService;
import com.hp.util.ResultJson;
import com.hp.util.Utils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/userRole")
public class UserRoleController {
    @Resource
    UserRoleService userRoleService;

    @RequestMapping("queryAll")
    public ModelAndView queryAll(UserRole userRole, Integer page, Integer limit, HttpServletResponse response) {
        ModelAndView model = new ModelAndView();
//        String id = GeneratID.getGeneratID();
//        System.out.println(username);
        System.out.println(userRole+"----------userRole-------------");
        List<UserRole> list = userRoleService.queryAll(userRole,page,limit);
        PageInfo<UserRole> userPageInfo = new PageInfo<UserRole>(list);
        System.out.println(list+"-----------list---------------");
        Utils.returnJson(ResultJson.success(userPageInfo), response);
        return model;

    }
    @RequestMapping("/pass")
    @ResponseBody
    public String pass(HttpServletResponse response,Integer id){
        int i = userRoleService.pass(id);
        Utils.returnJson(ResultJson.success(i), response);
        return null;
    }
    @RequestMapping("/nopass")
    @ResponseBody
    public String nopass(HttpServletResponse response,Integer id){
        int i = userRoleService.nopass(id);
        Utils.returnJson(ResultJson.success(i), response);
        return null;
    }

}
